package lgs.hm.annotation;

import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import lgs.hm.homework.work2.Car;
import lgs.hm.homework.work2.Work2;
import lgs.hm.homework.work3.GirFrend;
import lgs.hm.homework.work3.Villa;
import lgs.hm.homework.work3.Work3;
import lgs.hm.homework.work3.XiaoMing;

public class Main {
	
	public static void main(String[] args) {
		
		//实现基于Java的配置类加载Spring的应用程序上下文
		ApplicationContext ac = new AnnotationConfigApplicationContext(Work3.class);
		
		/*String[] names = ac.getBeanDefinitionNames();
		for (String name : names) {
			System.out.println(ac.getBean(name));
		}*/
		
		Map<String, XiaoMing> beansOfType = ac.getBeansOfType(XiaoMing.class);//根据类型获取对象
		System.out.println(beansOfType);
		GirFrend bean = ac.getBean(GirFrend.class);  //根据类型获取对象
		System.out.println(bean);
		Villa bean2 = ac.getBean(Villa.class);
		System.out.println(bean2);
		Object bean3 = ac.getBean("servant");     //根据名称获取对象
		System.out.println(bean3);
		
	}

	private static void main() {
		//实现基于Java的配置类加载Spring的应用上下文
		ApplicationContext ac = new AnnotationConfigApplicationContext(Work2.class);
		
		Map<String, Car> has = ac.getBeansOfType(Car.class); //用来获取某一类（包括子类）的所有的bean。
		System.out.println(has);
		
		Car bean = ac.getBean(Car.class);  //根据类型直接获取对象
		System.out.println(bean);
		
		/**
		 * 名称怎么来
		 * @Componen注解注入的，根据类名首字母小写
		 * @Bean注解注入的，就是方法名
		 */
		Car bean2 = (Car) ac.getBean("car");
		System.out.println(bean2);
		Object bean3 = ac.getBean("aaa");
		System.out.println(bean3);
	}

}
